package com.ruoyi.food.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.food.domain.OpmFoodSafeHidden;
import com.ruoyi.food.service.IOpmFoodSafeHiddenService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 食品质量安全隐患Controller
 *
 * @author cjie
 * @date 2021-07-24
 */
@Api(tags = " 食品质量安全隐患")
@RestController
@RequestMapping("/opmFoodSafeHidden")
public class OpmFoodSafeHiddenController extends BaseController {
    @Autowired
    private IOpmFoodSafeHiddenService opmFoodSafeHiddenService;

    /**
     * 查询食品质量安全隐患列表
     */
    @ApiOperation(value="查询食品质量安全隐患列表", notes="查询食品质量安全隐患列表")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:list")
    @GetMapping("/list")
    public TableDataInfo list(OpmFoodSafeHidden opmFoodSafeHidden) {
        startPage();
        List<OpmFoodSafeHidden> list = opmFoodSafeHiddenService.selectOpmFoodSafeHiddenList(opmFoodSafeHidden);
        return getDataTable(list);
    }

    /**
     * 导出食品质量安全隐患列表
     */
    @ApiOperation(value="导出食品质量安全隐患列表", notes="导出食品质量安全隐患列表")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:export")
    @Log(title = "食品质量安全隐患", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpmFoodSafeHidden opmFoodSafeHidden) throws IOException {
        List<OpmFoodSafeHidden> list = opmFoodSafeHiddenService.selectOpmFoodSafeHiddenList(opmFoodSafeHidden);
        ExcelUtil<OpmFoodSafeHidden> util = new ExcelUtil<OpmFoodSafeHidden>(OpmFoodSafeHidden.class);
        util.exportExcel(response, list, "食品质量安全隐患数据");
    }
    /**
     * 获取食品质量安全隐患详细信息
     */
    @ApiOperation(value="获取食品质量安全隐患详细信息", notes="获取食品质量安全隐患详细信息")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(opmFoodSafeHiddenService.selectOpmFoodSafeHiddenById(id));
    }

    /**
     * 新增食品质量安全隐患
     */
    @ApiOperation(value="新增食品质量安全隐患", notes="新增食品质量安全隐患")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:add")
    @Log(title = "食品质量安全隐患", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpmFoodSafeHidden opmFoodSafeHidden) {
        return toAjax(opmFoodSafeHiddenService.insertOpmFoodSafeHidden(opmFoodSafeHidden));
    }

    /**
     * 修改食品质量安全隐患
     */
    @ApiOperation(value="修改食品质量安全隐患", notes="修改食品质量安全隐患")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:edit")
    @Log(title = "食品质量安全隐患", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpmFoodSafeHidden opmFoodSafeHidden) {
        return toAjax(opmFoodSafeHiddenService.updateOpmFoodSafeHidden(opmFoodSafeHidden));
    }

    /**
     * 删除食品质量安全隐患
     */
    @ApiOperation(value="删除食品质量安全隐患", notes="删除食品质量安全隐患")
    @ApiImplicitParam(name = "ids", value = "食品质量安全隐患ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "food:opmFoodSafeHidden:remove")
    @Log(title = "食品质量安全隐患", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(opmFoodSafeHiddenService.deleteOpmFoodSafeHiddenByIds(ids));
    }
}
